from launch import LaunchDescription
from launch_ros.actions import Node
from ament_index_python.packages import get_package_share_directory
import os

def generate_launch_description():
    # 获取包目录
    pkg_dir = get_package_share_directory('aimotor_control')
    
    # 配置文件路径
    config_file = os.path.join(pkg_dir, 'config', 'motor_position.json')
    
    return LaunchDescription([
        Node(
            package='aimotor_control',
            executable='motor_control_node',
            name='aimotor_control',
            output='screen',
            parameters=[{
                # 通信参数
                'port': '/dev/rikiservo',
                'baudrate': 57600,
                'slave_id': 1,
                
                # 运动控制参数
                'default_speed': 200,
                'default_acc_time': 20,
                'pulses_per_revolution': 1000,
                
                # 位置查询参数
                'position_query_interval': 0.2,
                'position_save_interval': 2.0,
                'position_change_threshold': 50.0,
                
                # 关键改进：启用绝对位置模式
                'enable_absolute_positioning': True,
                
                # 软限位保护参数
                'soft_limit_min': -350000.0,
                'soft_limit_max': 350000.0,
                'limit_tolerance': 10.0,
                'emergency_stop_distance': 1000.0,
                
                # 数据持久化参数
                'position_file': '/home/rikibot/robot_ws/src/aimotor_control/config/motor_position.json'
            }]
        ),
    ])